/**
 * <copyright>
 * </copyright>
 *
 * $Id$
 */
package org.dengues.model.database.impl;

import java.util.Collection;

import org.dengues.model.database.DBColumn;
import org.dengues.model.database.DBTable;
import org.dengues.model.database.DatabasePackage;

import org.dengues.model.project.CDCConnType;
import org.eclipse.emf.common.notify.Notification;
import org.eclipse.emf.common.notify.NotificationChain;

import org.eclipse.emf.common.util.EList;

import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.InternalEObject;

import org.eclipse.emf.ecore.impl.ENotificationImpl;

import org.eclipse.emf.ecore.util.EObjectContainmentWithInverseEList;
import org.eclipse.emf.ecore.util.InternalEList;

/**
 * <!-- begin-user-doc -->
 * An implementation of the model object '<em><b>DB Table</b></em>'.
 * <!-- end-user-doc -->
 * <p>
 * The following features are implemented:
 * <ul>
 *   <li>{@link org.dengues.model.database.impl.DBTableImpl#getColumns <em>Columns</em>}</li>
 *   <li>{@link org.dengues.model.database.impl.DBTableImpl#isOnlyRead <em>Only Read</em>}</li>
 *   <li>{@link org.dengues.model.database.impl.DBTableImpl#getMetaType <em>Meta Type</em>}</li>
 *   <li>{@link org.dengues.model.database.impl.DBTableImpl#isActivateCdc <em>Activate Cdc</em>}</li>
 *   <li>{@link org.dengues.model.database.impl.DBTableImpl#getCdcConn <em>Cdc Conn</em>}</li>
 * </ul>
 * </p>
 *
 * @generated
 */
public class DBTableImpl extends DiagramChildImpl implements DBTable {
    /**
     * <!-- begin-user-doc -->
     * <!-- end-user-doc -->
     * @generated
     */
    public static final String copyright = "// ============================================================================\r\n//\r\n// Copyright (C) 2006-2007 Dengues\r\n//\r\n// Google Group: http://groups.google.com/group/dengues\r\n// QQ Group: 24885404\r\n//\r\n// This library is free software; you can redistribute it and/or\r\n// modify it under the terms of the GNU Lesser General Public\r\n// License as published by the Free Software Foundation; either\r\n// version 2.1 of the License.\r\n//\r\n// This library is distributed in the hope that it will be useful,\r\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\r\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\r\n// Lesser General Public License for more details.\r\n//\r\n// You should have received a copy of the GNU General Public License\r\n// along with this program; if not, write to the Free Software\r\n// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.\r\n//\r\n// ============================================================================\r\n";

    /**
     * The cached value of the '{@link #getColumns() <em>Columns</em>}' containment reference list.
     * <!-- begin-user-doc -->
     * <!-- end-user-doc -->
     * @see #getColumns()
     * @generated
     * @ordered
     */
    protected EList<DBColumn> columns;

    /**
     * The default value of the '{@link #isOnlyRead() <em>Only Read</em>}' attribute.
     * <!-- begin-user-doc -->
     * <!-- end-user-doc -->
     * @see #isOnlyRead()
     * @generated
     * @ordered
     */
    protected static final boolean ONLY_READ_EDEFAULT = false;

    /**
     * The cached value of the '{@link #isOnlyRead() <em>Only Read</em>}' attribute.
     * <!-- begin-user-doc -->
     * <!-- end-user-doc -->
     * @see #isOnlyRead()
     * @generated
     * @ordered
     */
    protected boolean onlyRead = ONLY_READ_EDEFAULT;

    /**
     * The default value of the '{@link #getMetaType() <em>Meta Type</em>}' attribute.
     * <!-- begin-user-doc -->
     * <!-- end-user-doc -->
     * @see #getMetaType()
     * @generated
     * @ordered
     */
    protected static final String META_TYPE_EDEFAULT = null;

    /**
     * The cached value of the '{@link #getMetaType() <em>Meta Type</em>}' attribute.
     * <!-- begin-user-doc -->
     * <!-- end-user-doc -->
     * @see #getMetaType()
     * @generated
     * @ordered
     */
    protected String metaType = META_TYPE_EDEFAULT;

    /**
     * The default value of the '{@link #isActivateCdc() <em>Activate Cdc</em>}' attribute.
     * <!-- begin-user-doc -->
     * <!-- end-user-doc -->
     * @see #isActivateCdc()
     * @generated
     * @ordered
     */
    protected static final boolean ACTIVATE_CDC_EDEFAULT = false;

    /**
     * The cached value of the '{@link #isActivateCdc() <em>Activate Cdc</em>}' attribute.
     * <!-- begin-user-doc -->
     * <!-- end-user-doc -->
     * @see #isActivateCdc()
     * @generated
     * @ordered
     */
    protected boolean activateCdc = ACTIVATE_CDC_EDEFAULT;

    /**
     * The cached value of the '{@link #getCdcConn() <em>Cdc Conn</em>}' reference.
     * <!-- begin-user-doc -->
     * <!-- end-user-doc -->
     * @see #getCdcConn()
     * @generated
     * @ordered
     */
    protected CDCConnType cdcConn;

    /**
     * <!-- begin-user-doc -->
     * <!-- end-user-doc -->
     * @generated
     */
    protected DBTableImpl() {
        super();
    }

    /**
     * <!-- begin-user-doc -->
     * <!-- end-user-doc -->
     * @generated
     */
    @Override
    protected EClass eStaticClass() {
        return DatabasePackage.Literals.DB_TABLE;
    }

    /**
     * <!-- begin-user-doc -->
     * <!-- end-user-doc -->
     * @generated
     */
    public EList<DBColumn> getColumns() {
        if (columns == null) {
            columns = new EObjectContainmentWithInverseEList<DBColumn>(DBColumn.class, this, DatabasePackage.DB_TABLE__COLUMNS, DatabasePackage.DB_COLUMN__TABLE);
        }
        return columns;
    }

    /**
     * <!-- begin-user-doc -->
     * <!-- end-user-doc -->
     * @generated
     */
    public boolean isOnlyRead() {
        return onlyRead;
    }

    /**
     * <!-- begin-user-doc -->
     * <!-- end-user-doc -->
     * @generated
     */
    public void setOnlyRead(boolean newOnlyRead) {
        boolean oldOnlyRead = onlyRead;
        onlyRead = newOnlyRead;
        if (eNotificationRequired())
            eNotify(new ENotificationImpl(this, Notification.SET, DatabasePackage.DB_TABLE__ONLY_READ, oldOnlyRead, onlyRead));
    }

    /**
     * <!-- begin-user-doc -->
     * <!-- end-user-doc -->
     * @generated
     */
    public String getMetaType() {
        return metaType;
    }

    /**
     * <!-- begin-user-doc -->
     * <!-- end-user-doc -->
     * @generated
     */
    public void setMetaType(String newMetaType) {
        String oldMetaType = metaType;
        metaType = newMetaType;
        if (eNotificationRequired())
            eNotify(new ENotificationImpl(this, Notification.SET, DatabasePackage.DB_TABLE__META_TYPE, oldMetaType, metaType));
    }

    /**
     * <!-- begin-user-doc -->
     * <!-- end-user-doc -->
     * @generated
     */
    public boolean isActivateCdc() {
        return activateCdc;
    }

    /**
     * <!-- begin-user-doc -->
     * <!-- end-user-doc -->
     * @generated
     */
    public void setActivateCdc(boolean newActivateCdc) {
        boolean oldActivateCdc = activateCdc;
        activateCdc = newActivateCdc;
        if (eNotificationRequired())
            eNotify(new ENotificationImpl(this, Notification.SET, DatabasePackage.DB_TABLE__ACTIVATE_CDC, oldActivateCdc, activateCdc));
    }

    /**
     * <!-- begin-user-doc -->
     * <!-- end-user-doc -->
     * @generated
     */
    public CDCConnType getCdcConn() {
        if (cdcConn != null && cdcConn.eIsProxy()) {
            InternalEObject oldCdcConn = (InternalEObject)cdcConn;
            cdcConn = (CDCConnType)eResolveProxy(oldCdcConn);
            if (cdcConn != oldCdcConn) {
                if (eNotificationRequired())
                    eNotify(new ENotificationImpl(this, Notification.RESOLVE, DatabasePackage.DB_TABLE__CDC_CONN, oldCdcConn, cdcConn));
            }
        }
        return cdcConn;
    }

    /**
     * <!-- begin-user-doc -->
     * <!-- end-user-doc -->
     * @generated
     */
    public CDCConnType basicGetCdcConn() {
        return cdcConn;
    }

    /**
     * <!-- begin-user-doc -->
     * <!-- end-user-doc -->
     * @generated
     */
    public void setCdcConn(CDCConnType newCdcConn) {
        CDCConnType oldCdcConn = cdcConn;
        cdcConn = newCdcConn;
        if (eNotificationRequired())
            eNotify(new ENotificationImpl(this, Notification.SET, DatabasePackage.DB_TABLE__CDC_CONN, oldCdcConn, cdcConn));
    }

    /**
     * <!-- begin-user-doc -->
     * <!-- end-user-doc -->
     * @generated
     */
    @SuppressWarnings("unchecked")
    @Override
    public NotificationChain eInverseAdd(InternalEObject otherEnd, int featureID, NotificationChain msgs) {
        switch (featureID) {
            case DatabasePackage.DB_TABLE__COLUMNS:
                return ((InternalEList<InternalEObject>)(InternalEList<?>)getColumns()).basicAdd(otherEnd, msgs);
        }
        return super.eInverseAdd(otherEnd, featureID, msgs);
    }

    /**
     * <!-- begin-user-doc -->
     * <!-- end-user-doc -->
     * @generated
     */
    @Override
    public NotificationChain eInverseRemove(InternalEObject otherEnd, int featureID, NotificationChain msgs) {
        switch (featureID) {
            case DatabasePackage.DB_TABLE__COLUMNS:
                return ((InternalEList<?>)getColumns()).basicRemove(otherEnd, msgs);
        }
        return super.eInverseRemove(otherEnd, featureID, msgs);
    }

    /**
     * <!-- begin-user-doc -->
     * <!-- end-user-doc -->
     * @generated
     */
    @Override
    public Object eGet(int featureID, boolean resolve, boolean coreType) {
        switch (featureID) {
            case DatabasePackage.DB_TABLE__COLUMNS:
                return getColumns();
            case DatabasePackage.DB_TABLE__ONLY_READ:
                return isOnlyRead() ? Boolean.TRUE : Boolean.FALSE;
            case DatabasePackage.DB_TABLE__META_TYPE:
                return getMetaType();
            case DatabasePackage.DB_TABLE__ACTIVATE_CDC:
                return isActivateCdc() ? Boolean.TRUE : Boolean.FALSE;
            case DatabasePackage.DB_TABLE__CDC_CONN:
                if (resolve) return getCdcConn();
                return basicGetCdcConn();
        }
        return super.eGet(featureID, resolve, coreType);
    }

    /**
     * <!-- begin-user-doc -->
     * <!-- end-user-doc -->
     * @generated
     */
    @SuppressWarnings("unchecked")
    @Override
    public void eSet(int featureID, Object newValue) {
        switch (featureID) {
            case DatabasePackage.DB_TABLE__COLUMNS:
                getColumns().clear();
                getColumns().addAll((Collection<? extends DBColumn>)newValue);
                return;
            case DatabasePackage.DB_TABLE__ONLY_READ:
                setOnlyRead(((Boolean)newValue).booleanValue());
                return;
            case DatabasePackage.DB_TABLE__META_TYPE:
                setMetaType((String)newValue);
                return;
            case DatabasePackage.DB_TABLE__ACTIVATE_CDC:
                setActivateCdc(((Boolean)newValue).booleanValue());
                return;
            case DatabasePackage.DB_TABLE__CDC_CONN:
                setCdcConn((CDCConnType)newValue);
                return;
        }
        super.eSet(featureID, newValue);
    }

    /**
     * <!-- begin-user-doc -->
     * <!-- end-user-doc -->
     * @generated
     */
    @Override
    public void eUnset(int featureID) {
        switch (featureID) {
            case DatabasePackage.DB_TABLE__COLUMNS:
                getColumns().clear();
                return;
            case DatabasePackage.DB_TABLE__ONLY_READ:
                setOnlyRead(ONLY_READ_EDEFAULT);
                return;
            case DatabasePackage.DB_TABLE__META_TYPE:
                setMetaType(META_TYPE_EDEFAULT);
                return;
            case DatabasePackage.DB_TABLE__ACTIVATE_CDC:
                setActivateCdc(ACTIVATE_CDC_EDEFAULT);
                return;
            case DatabasePackage.DB_TABLE__CDC_CONN:
                setCdcConn((CDCConnType)null);
                return;
        }
        super.eUnset(featureID);
    }

    /**
     * <!-- begin-user-doc -->
     * <!-- end-user-doc -->
     * @generated
     */
    @Override
    public boolean eIsSet(int featureID) {
        switch (featureID) {
            case DatabasePackage.DB_TABLE__COLUMNS:
                return columns != null && !columns.isEmpty();
            case DatabasePackage.DB_TABLE__ONLY_READ:
                return onlyRead != ONLY_READ_EDEFAULT;
            case DatabasePackage.DB_TABLE__META_TYPE:
                return META_TYPE_EDEFAULT == null ? metaType != null : !META_TYPE_EDEFAULT.equals(metaType);
            case DatabasePackage.DB_TABLE__ACTIVATE_CDC:
                return activateCdc != ACTIVATE_CDC_EDEFAULT;
            case DatabasePackage.DB_TABLE__CDC_CONN:
                return cdcConn != null;
        }
        return super.eIsSet(featureID);
    }

    /**
     * <!-- begin-user-doc -->
     * <!-- end-user-doc -->
     * @generated
     */
    @Override
    public String toString() {
        if (eIsProxy()) return super.toString();

        StringBuffer result = new StringBuffer(super.toString());
        result.append(" (onlyRead: ");
        result.append(onlyRead);
        result.append(", metaType: ");
        result.append(metaType);
        result.append(", activateCdc: ");
        result.append(activateCdc);
        result.append(')');
        return result.toString();
    }

} //DBTableImpl
